//
//  EFMenuCollectionCell.m
//  ESPTablet
//
//  Created by Javor on 14-8-12.
//  Copyright (c) 2014年 Javor. All rights reserved.
//

#import "EFMenuCollectionCell.h"
//#ifdef NEED_FRAMEWORK
//#import <IOSESPBaseFramework/FileUtil.h>
//#else
#import "FileUtil.h"
//#endif
#import "EnvironmentVariable.h"
#import "Constant.h"

@interface EFMenuCollectionCell(){
    UIImageView *_icon;
    UILabel *_label;
    UILabel *_indicateLabel;//右上角提示
}

@end

@implementation EFMenuCollectionCell
@synthesize imagePath = _imagePath, title = _title;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = [UIColor orangeColor];
        _icon = [[UIImageView alloc] init];
        _label = [[UILabel alloc] init];
        _indicateLabel = [[UILabel alloc] init];
        _imageWidth = 0;
        _imageHeight = 0;
        _titleHeight = 0;
        self.indicateCount = 0;
        
        [self.contentView addSubview:_icon];
        [self.contentView addSubview:_label];
        [self.contentView addSubview:_indicateLabel];
    }
    return self;
}

-(void) creationComplete{
    [self changeCellWithImageWidth:_imageWidth imageHeight:_imageHeight titleHeight:_titleHeight];
    _indicateLabel.font = [UIFont systemFontOfSize:_indicateLabel.frame.size.width/3*2];
    _label.textAlignment = NSTextAlignmentCenter;
    _indicateLabel.textAlignment = NSTextAlignmentCenter;
    _indicateLabel.textColor = [UIColor whiteColor];
    _indicateLabel.layer.backgroundColor = [UIColor redColor].CGColor;

}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    _icon.layer.shadowColor = [UIColor yellowColor].CGColor;
    _icon.layer.shadowOffset = CGSizeMake(0.5, 0.5);
    _icon.layer.shadowOpacity = 0.5;
    _icon.layer.shadowRadius = 6.0;
    return YES;
}

-(void)iconTouchDown{
    _icon.layer.shadowColor = [UIColor yellowColor].CGColor;
    _icon.layer.shadowOffset = CGSizeMake(0.5, 0.5);
    _icon.layer.shadowOpacity = 0.5;
    _icon.layer.shadowRadius = 6.0;
}

-(void)iconTouchUp{
    _icon.layer.shadowOpacity = 0;
}

-(void)setImagePath:(NSString *)aImagePath{
    _imagePath = aImagePath;
    if(![_imagePath isEqualToString:@""]){
        NSString *path = [[EnvironmentVariable getVersionPath] stringByAppendingString:@"/Image"];
       _image = [[UIImage alloc]initWithData:[FileUtil getFileDataWithPath:_imagePath andTypePath:path]];
//        UIImage *iconImage = [UIImage imageWithContentsOfFile:_imagePath];
    }
    _icon.image = _image;
}

-(void)setImage:(UIImage *)image{
    _image = image;
    _icon.image = _image;
}

-(void)setTitle:(NSString *)aTitle{
    _title = aTitle;
    _label.text = _title;
}

-(void)setTitleColor:(UIColor *)titleColor{
    _titleColor = titleColor;
    _label.textColor = titleColor;
}

-(void)setTitleFontSize:(CGFloat)titleFontSize{
    _titleFontSize = titleFontSize;
    _label.font = FONT(titleFontSize);
}

-(void)setIndicateLabelHidden:(BOOL)indicateLabelHidden{
    _indicateLabelHidden = indicateLabelHidden;
    _indicateLabel.hidden = indicateLabelHidden;
}

-(void) setIndicateCount:(int)indicateCount{
    _indicateCount = indicateCount;
    _indicateLabel.text = [NSString stringWithFormat:@"%d",indicateCount];
    if (indicateCount == 0) {
        self.indicateLabelHidden = YES;
    }else{
        self.indicateLabelHidden = NO;
    }
}

-(void)changeCellWithImageWidth:(CGFloat)imageWidth imageHeight:(CGFloat)imageHeight titleHeight:(CGFloat)titleHeight{
    _icon.frame = CGRectMake(0, 0, imageWidth, imageHeight);
    _label.frame = CGRectMake(_icon.frame.origin.x, _icon.frame.size.height + 5, imageWidth, titleHeight);
    _indicateLabel.frame = CGRectMake(_icon.frame.size.width -  imageWidth/3, _icon.frame.origin.y, imageWidth/3, imageHeight/3);
    _indicateLabel.layer.cornerRadius = _indicateLabel.frame.size.width/2;
//    NSLog(@"右上角指示弧度：%f",_indicateLabel.frame.size.width/2);
}

@end
